from django.contrib.contenttypes.fields import GenericRelation
from django.db import models
from django.shortcuts import reverse
from django.utils.translation import gettext_lazy as _
from audit.models import AuditManagement
from lib.django import models as mymodels
from .project import Project
from lib.django import models as mymodels

from .lib import ProjectSubMixin

class InitiationData(ProjectSubMixin, models.Model):
    project = models.ForeignKey(
        verbose_name=_("项目"),
        to=Project,
        on_delete=models.CASCADE,
        blank=True
    )

    time = models.DateField(
        verbose_name=_("时间"),
        auto_now_add=True
    )

    version = models.IntegerField(
        verbose_name=_("版本号"),
        editable=False,
    )

    date_new_drug_registration_submission = models.DateField(
        verbose_name=_("提交新药注册申请日期"), null=True, blank=True, default=None
    )
    
    date_investigational_drug_preparation_completion = models.DateField(
        verbose_name=_("试验药品完成准备日期"), null=True, blank=True, default=None
    )
    
    filing_location = models.CharField(
        verbose_name=_("归档地点"),
        max_length=255,
        null=True,
        blank=True,
        default=None
    )
    
    note = models.TextField(
        verbose_name="备注信息",
        blank=True,
        default="",
    )

    is_draft = mymodels.YesNoField(
        verbose_name=_("草稿"),
        blank=True,
        help_text=_("不显示在审核列表"),
        default=False,
    )

    audit_management = GenericRelation(
        AuditManagement,
        content_type_field='content_type',
        object_id_field='object_id',
        verbose_name=_("审核管理")
    )
    
    class Meta:
        default_permissions=[]
        db_table="project_initiation_data"
        verbose_name=_("项目立项资料")
        verbose_name_plural= verbose_name

    @classmethod
    def get_link(cls, project_id, id):
        return reverse("project:initiation/detail", kwargs={'project_pk': project_id, 'pk': id})

